//
//  SXAccuntTool.m
//  Weibo1
//
//  Created by dfpo on 15/3/16.
//  Copyright (c) 2015年 dfpo. All rights reserved.
//
#define SXAccountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"account.archive"]
#import "SXAccountTool.h"

@implementation SXAccountTool
+ (void)saveAccount:(SXAccount *)account {
    
    [NSKeyedArchiver archiveRootObject:account toFile:SXAccountPath];
}
+ (SXAccount *)account {
    SXAccount * account = [NSKeyedUnarchiver unarchiveObjectWithFile:SXAccountPath];
    // 验证账号是否过期
    long long expires_in = [account.expires_in longLongValue];
    NSDate *expiresTime = [account.created_time dateByAddingTimeInterval:expires_in];
    NSDate *nowTime = [NSDate date];
    NSComparisonResult result = [expiresTime compare:nowTime];
    if (result != NSOrderedDescending) {
        // 过期
        return  nil;
    }
    return account;
}
@end
